package com.ruoyi.finance.szUser.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.finance.szUser.domain.SzUser;
import com.ruoyi.finance.szUser.service.SzUserInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 平台用户Controller
 * 
 * @author wangmh
 * @date 2023-10-07
 */
@RestController
@RequestMapping("/finance/szUser")
public class SzUserController extends BaseController
{
    @Autowired
    private SzUserInfoService szUserService;

    /**
     * 查询平台用户列表
     */
    @PreAuthorize("@ss.hasPermi('finance:szUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(SzUser szUser){
        startPage();
        List<SzUser> list = szUserService.selectSzUserList(szUser);
        return getDataTable(list);
    }

    /**
     * 导出平台用户列表
     */
    @PreAuthorize("@ss.hasPermi('finance:szUser:export')")
    @Log(title = "平台用户-导出用户列表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SzUser szUser) {
        List<SzUser> list = szUserService.selectSzUserList(szUser);
        ExcelUtil<SzUser> util = new ExcelUtil<SzUser>(SzUser.class);
        return util.exportExcel(list, "平台用户数据");
    }

    /**
     * 获取平台用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:szUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(szUserService.selectSzUserById(id));
    }

    /**
     * 新增平台用户
     */
    @PreAuthorize("@ss.hasPermi('finance:szUser:add')")
    @Log(title = "平台用户-新增用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzUser szUser) {
        return szUserService.insertSzUser(szUser);
    }

    /**
     * 修改平台用户
     */
    @PreAuthorize("@ss.hasPermi('finance:szUser:edit')")
    @Log(title = "平台用户-修改用户资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzUser szUser) {
        return szUserService.updateSzUser(szUser);
    }

    /**
     * 重置平台用户登录密码
     */
    @PreAuthorize("@ss.hasPermi('finance:szUser:resetLoginPassword')")
    @Log(title = "平台用户-重置登录密码", businessType = BusinessType.UPDATE)
	@GetMapping("/resetLoginPassword/{ids}")
    public AjaxResult resetLoginPassword(@PathVariable Long[] ids) {
        return szUserService.resetLoginPassword(ids);
    }

    /**
     * 重置支付密码
     * @param ids
     * @return
     */
    @PreAuthorize("@ss.hasPermi('finance:szUser:resetPaymentPassword')")
    @Log(title = "平台用户-重置支付密码", businessType = BusinessType.UPDATE)
    @GetMapping("/resetPaymentPassword/{ids}")
    public AjaxResult resetPaymentPassword(@PathVariable Long[] ids) {
        return szUserService.resetPaymentPassword(ids);
    }

    /**
     * 注销/启用
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('finance:szUser:logoutOrEnable')")
    @Log(title = "平台用户-注销/启用", businessType = BusinessType.UPDATE)
    @PostMapping("/logoutOrEnable")
    public AjaxResult logoutOrEnable(Long id, String type) {
        return szUserService.logoutOrEnable(id, type);
    }

    /**
     * 删除账号
     * @param id
     * @param type
     * @return
     */
    @PreAuthorize("@ss.hasPermi('finance:szUser:deleteUser')")
    @Log(title = "平台用户-删除", businessType = BusinessType.UPDATE)
    @PostMapping("/delete")
    public AjaxResult delete(Long id, String type) {
        return szUserService.delete(id, type);
    }



}
